<html>
<head>
<meta http-equiv="Content-Language" content="zh-tw">
<script lang="java" language="javascript" type="text/javascript" src="public_var.js"></script>
<script lang="java" language="javascript" type="text/javascript" src="public_function.js"></script>
<script lang="java" language="javascript" type="text/javascript" src="dao.js"></script>
</head>
<body bgcolor="#3A6EA5" onload="javascript:parent.document.all.ifrProjectTask.height=document.all.tblWkfList.offsetHeight;">
<script lang="java" language="javascript" type="text/javascript">
function changeTaskCompletion(p_task_id){
  openConn(db_type);
  updateTaskCompletion(p_task_id);
  closeConn();
  
  window.location.href="personal_project_task.htm";
}

function CloseOrOpen(p_owner_id,project_id,parent_task_id){
	//alert(p_owner_id);
	//alert(project_id);
	//alert(parent_task_id);
	var recTaskList = getActiveProjectTaskList(p_owner_id,project_id,parent_task_id);
	var v_show = true;
	
	while(!recTaskList.EOF){
		v_HaveSubTask = isHaveSubTask(recTaskList.Fields("task_id").Value);
	  if(document.getElementById('task' + recTaskList.Fields("task_id").Value).style.display==''){
	  	v_show=true;
	  }
	  else{
	  	v_show=false;
	  }
	  //alert(v_show);
		document.getElementById('task' + recTaskList.Fields("task_id").Value).style.display=(v_show ? 'none' : '');
		//alert(recTaskList.Fields("task_id").value);
		if(v_HaveSubTask){
			CloseOrOpen(p_owner_id,project_id,recTaskList.Fields("task_id").Value);
		}
		
		recTaskList.moveNext;
	}
}

openConn(db_type);

try{
	var activeProjectList = getActiveProjectList(v_owner);

	document.write("<table id='tblWkfList'><tr><td>");
	document.write("<ol>");
	while(!activeProjectList.EOF){
		dDeadLine = new Date(activeProjectList.Fields("dead_line").Value);
		document.write("<li");
		document.write(activeProjectList.Fields("completion_of").Value==100 ? " style='text-decoration: line-through'>" : ">");
		document.write(activeProjectList.Fields("project_name").Value);
		document.write("(<font color='blue'>");
		document.write(dDeadLine.format('yyyy/MM/dd'));
		document.write("</font>)");
		document.write("<input type='text' size='3' value='" + activeProjectList.Fields("completion_of").Value + "' style='text-align: right;BORDER-TOP: 0px;BORDER-LEFT: 0px;BORDER-RIGHT: 0px;BORDER-BOTTOM: 0px;background-color: #3A6EA5;' readonly>");
		document.write("%</li>");
		outputTask(v_owner,activeProjectList.Fields("project_id").Value,0);
		activeProjectList.moveNext;
	}
	document.write("</ol>");
	document.write("</td></tr></table>");
}
catch(e){
	alert("WKF ERROR");
}

closeConn();

function outputTask(p_owner_id,project_id,parent_task_id){

	var recTaskList = getActiveProjectTaskList(p_owner_id,project_id,parent_task_id);
	if(debug){alert("getActiveProjectTaskList(p_owner_id,project_id,parent_task_id) OK!!");}
	var v_HaveSubTask=false;
	document.write("<ol>");

	try{
		while(!recTaskList.EOF){
			v_HaveSubTask = isHaveSubTask(recTaskList.Fields("task_id").Value);
			dDeadLine = new Date(recTaskList.Fields("task_deadline").Value);
		
			document.write("<li");
			document.write(recTaskList.Fields("completion_of").Value==100 ? " style='text-decoration: line-through' " : " ");
			document.write(" id='task" + recTaskList.Fields("task_id").value + "' ondblclick=\"javascript:openConn('" + db_type + "');CloseOrOpen('" + p_owner_id + "','" + project_id + "'," + recTaskList.Fields("task_id").value + ");closeConn();\"");
			document.write(">");
			document.write(recTaskList.Fields("task_id").value);
			document.write(" ");
			document.write(recTaskList.Fields("task_title").Value);
			document.write("(<font color='red'>");
			document.write(dDeadLine.format('yyyy/MM/dd'));
			document.write("</font>)");	
			document.write("<input type='text' size='3' style='text-align: right;BORDER-TOP: 0px;BORDER-LEFT: 0px;BORDER-RIGHT: 0px;BORDER-BOTTOM: 0px;background-color: #3A6EA5;' name='t");
			document.write(recTaskList.Fields("task_id").Value);
			document.write("' value='" + recTaskList.Fields("completion_of").Value + "'");
			document.write(v_HaveSubTask ? " readonly" : " onchange='javascript:changeTaskCompletion(" + recTaskList.Fields("task_id").Value + ")'");
			document.write("/>%");	
			document.write("</li>");
			if(v_HaveSubTask){
				outputTask(p_owner_id,project_id,recTaskList.Fields("task_id").Value);
			}
			recTaskList.moveNext;
		}

		document.write("</ol>");
	}
	catch(e){
		alert("TASK ERROR");
	}
}
</script>
</body>
</html>